import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import { usePermissStore } from "../store/permiss";
import Home from "../views/home.vue";
// import Agent from '../views/manage/agent/index.vue';

const routes: RouteRecordRaw[] = [
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "登录",
    },
    component: () =>
      import(/* webpackChunkName: "login" */ "../views/login.vue"),
  },
  {
    path: "/",
    redirect: "/entry",
  },
  {
    path: "/",
    name: "Home",
    component: Home,
    children: [
      //////////////////////////////////////////// 代理商管理 //////////////////////////////////////////////////////
      {
        path: "/entry",
        name: "entry",
        meta: {
          title: "欢迎页",
          permiss: "99",
        },
        component: () =>
          import(/* webpackChunkName: "table" */ "../views/entry/index.vue"),
      },
      //////////////////////////////////////////// 代理商管理 //////////////////////////////////////////////////////
      {
        path: "/manage/agent",
        name: "basetable",
        meta: {
          title: "代理管理",
          permiss: "1",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/manage/agent/index.vue"
          ),
      },
      //////////////////////////////////////////// 用户管理 //////////////////////////////////////////////////////
      {
        path: "/manage/users",
        name: "users",
        meta: {
          title: "用户管理",
          permiss: "2",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/manage/user/index.vue"
          ),
      },
      //////////////////////////////////////////// 普通会员 //////////////////////////////////////////////////////
      {
        path: "/vip/pack",
        name: "vipPack",
        meta: {
          title: "会员套餐",
          permiss: "3",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/vip/pack/index.vue"
          ),
      },
      {
        path: "/vip/series",
        name: "vipSeries",
        meta: {
          title: "系列管理",
          permiss: "4",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/vip/series/index.vue"
          ),
      },
      //////////////////////////////////////////// 车主服务 //////////////////////////////////////////////////////
      {
        path: "/carOwner/pageConfig",
        name: "pageConfig",
        meta: {
          title: "车主页面配置",
          permiss: "7",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/carOwner/pageConfig/index.vue"
          ),
      },
      {
        path: "/carOwner/serviceNote",
        name: "serviceNote",
        meta: {
          title: "车主服务说明",
          permiss: "8",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/carOwner/serviceNote/index.vue"
          ),
      },

      //////////////////////////////////////////// 签约订单 //////////////////////////////////////////////////////
      {
        path: "/order/signedOrder",
        name: "baseform",
        meta: {
          title: "签约订单",
          permiss: "9",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/order/signedOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 通行订单 //////////////////////////////////////////////////////
      {
        path: "/order/passOrder",
        name: "passOrder",
        meta: {
          title: "通行订单",
          permiss: "12",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/order/passOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 奖励订单 //////////////////////////////////////////////////////
      {
        path: "/order/rewardOrder",
        name: "rewardOrder",
        meta: {
          title: "奖励订单",
          permiss: "13",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/order/rewardOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 预充金订单 //////////////////////////////////////////////////////
      {
        path: "/order/prePaymentOrder",
        name: "prePaymentOrder",
        meta: {
          title: "预充金订单",
          permiss: "14",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/order/prePaymentOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 提现订单 //////////////////////////////////////////////////////
      {
        path: "/order/withdrawalOrder",
        name: "withdrawalOrder",
        meta: {
          title: "提现订单",
          permiss: "15",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/order/withdrawalOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 加油订单 //////////////////////////////////////////////////////
      {
        path: "/valueAddedService/refuelOrder",
        name: "refuelOrder",
        meta: {
          title: "加油订单",
          permiss: "16",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/valueAddedService/refuelOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 加油退款订单 //////////////////////////////////////////////////////
      {
        path: "/valueAddedService/refuelRefundOrder",
        name: "refuelRefundOrder",
        meta: {
          title: "加油退款订单",
          permiss: "17",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/valueAddedService/refuelRefundOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 业务订单 //////////////////////////////////////////////////////
      {
        path: "/order/businessOrder",
        name: "businessOrder",
        meta: {
          title: "业务订单",
          permiss: "18",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/order/businessOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 门店报备 //////////////////////////////////////////////////////
      {
        path: "/storefront/reporting",
        name: "reporting",
        meta: {
          title: "门店报备",
          permiss: "19",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/storefront/reporting/index.vue"
          ),
      },
      //////////////////////////////////////////// 员工管理 //////////////////////////////////////////////////////
      {
        path: "/administrator/accountList",
        name: "accountList",
        meta: {
          title: "账号列表",
          permiss: "20",
        },
        component: () =>
          import(
            /* webpackChunkName: "import" */ "../views/administrator/accountList/index.vue"
          ),
      },
      {
        path: "/administrator/role",
        name: "role",
        meta: {
          title: "角色",
          permiss: "21",
        },
        component: () =>
          import(
            /* webpackChunkName: "import" */ "../views/administrator/role/index.vue"
          ),
      },
      //////////////////////////////////////////// 风控系统 //////////////////////////////////////////////////////
      {
        path: "/riskControl/jobMonitoring",
        name: "jobMonitoring",
        meta: {
          title: "作业监控",
          permiss: "22",
        },
        component: () =>
          import(
            /* webpackChunkName: "import" */ "../views/riskControl/jobMonitoring/index.vue"
          ),
      },
      //////////////////////////////////////////// 上传订单 //////////////////////////////////////////////////////
      {
        path: "/order/uploadOrder",
        name: "uploadOrder",
        meta: {
          title: "上传订单",
          permiss: "23",
        },
        component: () =>
          import(
            /* webpackChunkName: "import" */ "../views/order/uploadOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 通用配置 //////////////////////////////////////////////////////
      {
        path: "/systemConfig/universalConfig",
        name: "universalConfig",
        meta: {
          title: "通用配置",
          permiss: "24",
        },
        component: () =>
          import(
            /* webpackChunkName: "import" */ "../views/systemConfig/universalConfig/index.vue"
          ),
      },
      //////////////////////////////////////////// 注销参数设置 //////////////////////////////////////////////////////
      {
        path: "/valueAddedService/logoutParameterSettings",
        name: "logoutParameterSettings",
        meta: {
          title: "注销参数设置",
          permiss: "25",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/valueAddedService/logoutParameterSettings/index.vue"
          ),
      },
      //////////////////////////////////////////// 注销代办订单 //////////////////////////////////////////////////////
      {
        path: "/valueAddedService/logoutAgentOrder",
        name: "logoutAgentOrder",
        meta: {
          title: "注销代办订单",
          permiss: "26",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/valueAddedService/logoutAgentOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 洗车扣款订单订单 //////////////////////////////////////////////////////
      {
        path: "/valueAddedService/carWashOrder",
        name: "carWashOrder",
        meta: {
          title: "洗车扣款订单",
          permiss: "27",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/valueAddedService/carWashOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 洗车退款订单 //////////////////////////////////////////////////////
      {
        path: "/valueAddedService/carWashRefundOrder",
        name: "carWashRefundOrder",
        meta: {
          title: "洗车退款订单",
          permiss: "28",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/valueAddedService/carWashRefundOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 申领订单 //////////////////////////////////////////////////////
      {
        path: "/goodsAndMaterials/applyForOrder",
        name: "applyForOrder",
        meta: {
          title: "申领订单",
          permiss: "29",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/goodsAndMaterials/applyForOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 云瞻订单 //////////////////////////////////////////////////////
      {
        path: "/order/yunZhanOrder",
        name: "yunZhanOrder",
        meta: {
          title: "云瞻订单",
          permiss: "30",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/order/yunZhanOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 扣款订单 //////////////////////////////////////////////////////
      {
        path: "/order/vipOrder",
        name: "newVipOrder",
        meta: {
          title: "扣款订单",
          permiss: "31",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/order/vipOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 退款订单 //////////////////////////////////////////////////////
      {
        path: "/order/newRefundOrder",
        name: "newRefundOrder",
        meta: {
          title: "退款订单",
          permiss: "32",
        },
        component: () =>
          import(
            /* webpackChunkName: "table" */ "../views/order/newRefundOrder/index.vue"
          ),
      },
      //////////////////////////////////////////// 广告系统 //////////////////////////////////////////////////////
      //////////////////////////////////////////// 跑马灯管理 //////////////////////////////////////////////////////
      {
        path: "/advSystem/marquee",
        name: "marquee",
        meta: {
          title: "跑马灯管理",
          permiss: "33",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/advSystem/marquee/index.vue"
          ),
      },
      //////////////////////////////////////////// 公告管理 //////////////////////////////////////////////////////
      {
        path: "/advSystem/notice",
        name: "notice",
        meta: {
          title: "公告管理",
          permiss: "34",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/advSystem/notice/index.vue"
          ),
      },
      //////////////////////////////////////////// 广告管理 //////////////////////////////////////////////////////
      {
        path: "/advSystem/advertisement",
        name: "advertisement",
        meta: {
          title: "广告管理",
          permiss: "35",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/advSystem/advertisement/index.vue"
          ),
      },
      //////////////////////////////////////////// 支付配置 //////////////////////////////////////////////////////
      //////////////////////////////////////////// 支付场景 //////////////////////////////////////////////////////
      {
        path: "/payConfig/payScene",
        name: "payScene",
        meta: {
          title: "支付场景",
          permiss: "36",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/payConfig/payScene/index.vue"
          ),
      },
      //////////////////////////////////////////// 关联支付场景 //////////////////////////////////////////////////////
      {
        path: "/payConfig/assnPayScene",
        name: "assnPayScene",
        meta: {
          title: "关联支付场景",
          permiss: "37",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/payConfig/assnPayScene/index.vue"
          ),
      },
      //////////////////////////////////////////// 营销系统 //////////////////////////////////////////////////////
      //////////////////////////////////////////// 营销任务列表 //////////////////////////////////////////////////////
      {
        path: "/marketConfig/marketTaskList",
        name: "marketTaskList",
        meta: {
          title: "营销任务列表",
          permiss: "38",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/marketConfig/marketTaskList/index.vue"
          ),
      },
      //////////////////////////////////////////// 关联支付场景 //////////////////////////////////////////////////////
      {
        path: "/marketConfig/couponList",
        name: "couponList",
        meta: {
          title: "优惠券列表",
          permiss: "39",
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ "../views/marketConfig/couponList/index.vue"
          ),
      }
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem("X-Access-Token");
  if (to.path !== "/login") {
    if (token) {
      next();
    } else {
      next("/login");
    }
  } else {
    next();
  }
  // const permiss = usePermissStore();
});

export default router;
